package com.zlx.guguanjia.mapper.provider;

import com.zlx.guguanjia.entity.QualificationConfiguration;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @Author 周罗校
 * @Description 动态语句拼接语句
 * @ClassName QualificationProvider
 * @date 2020.10.26 11:08:02
 * 该版权归周罗校所有，最终解释权以官方为准
 */
public class QualificationProvider {

    public String selectPage(QualificationConfiguration configuration){
        StringBuilder sb = new StringBuilder();
        sb.append("" +
                "SELECT " +
                "qu.*,uu.name upload_name,cu.name  check_name  " +
                "FROM " +
                "qualification qu " +
                "LEFT JOIN sys_user uu ON qu.upload_user_id = uu.id " +
                "LEFT JOIN sys_user cu ON qu.check_user_id = cu.id " +
                "WHERE  " +
                "qu.del_flag = 0 ");
        if (!StringUtils.isEmpty(configuration.getType())){
            sb.append("And qu.type = #{type} ");
        }
        if (!StringUtils.isEmpty(configuration.getCheck())){
            sb.append("And qu.`check` = #{check} ");
        }
        if (!StringUtils.isEmpty(configuration.getStartDate())){
            sb.append("And qu.update_date>=#{startDate} ");
        }
        if (!StringUtils.isEmpty(configuration.getEndDate())){
            sb.append("And qu.update_date <= #{endDate} ");
        }

        return sb.toString();
    }
}
